import React from 'react';
import Child from './01-Child-子传父';

class Parent extends React.Component {
  state = {
    money: 0,
  };

  // 1 父组件定义一个函数传递给子组件
  giveMoney = (money) => {
    console.log('子组件的消息', money);
    this.setState({
      money: money,
    });
  };

  render() {
    return (
      // 父组件
      <div className="parent">
        <h1>父组件</h1>
        <div>我继承了：{this.props.money - this.state.money}块</div>
        <hr />
        <Child giveMoney={this.giveMoney} money={this.state.money} />
      </div>
    );
  }
}
export default Parent;
